package com.bw.zg3park2212.repair

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bumptech.glide.Glide
import com.bw.base.entity.RepairAddParam
import com.bw.base.entity.RepairEntityItem
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.ActivityRepairXiangBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/RepairXiangActivity")
class RepairXiangActivity : BaseActivity<ActivityRepairXiangBinding,RepairViewModel>() {
    @Autowired
   lateinit var rxid:RepairEntityItem
    override fun intitView() {
        ARouter.getInstance().inject(this)
        viewmodel.repairxiang(rxid.id)
    }

    override fun intitData() {
        viewmodel.repairXiangSuccse.observe(this){
            binding.rxOrderNumber.text="工单号:"+it.orderNumber
            binding.rxRepairName.text="报修姓名:"+it.repairName
            binding.rxRepairLocation.text="报修位置:"+it.repairLocation
            binding.rxRepairTime.text="报修时间:"+it.repairTime
            binding.rxContactMethod.text="联系方式:"+it.contactMethod
            binding.rxFaultDescription.text="故障描述:"+it.faultDescription
            Glide.with(this).load(it.faultPhotos).into(binding.rxImage)
            if (it.processingStatus=="处理中"){
                binding.tv2.setTextColor(resources.getColor(R.color.color_kongxian))
            }else if (it.processingStatus=="已完成"){
                binding.tv2.setTextColor(resources.getColor(R.color.color_kongxian))
                binding.tv3.setTextColor(resources.getColor(R.color.color_kongxian))
            }
            binding.btn1.setOnClickListener {it1->
                if (it.processingStatus=="待处理"){
                    val repairAddParam=RepairAddParam()
                    repairAddParam.processingStatus="处理中"
                    viewmodel.repairUp(it.id,repairAddParam)
                }
            }
            binding.btn2.setOnClickListener {it2->
                if (it.processingStatus=="处理中"){
                    val repairAddParam=RepairAddParam()
                    repairAddParam.processingStatus="已完成"
                    viewmodel.repairUp(it.id,repairAddParam)
                }
            }

        }
        viewmodel.repairUpSuccse.observe(this){
            ToastUtils.showLong("修改成功")
            finish()
        }
    }

}